/* dtim.c
 * Project 3
 * Georgii Tkachuk, Brentton Garber
 * georgii.t@gmail.com btgarber@asu.edu 
 * CSE 325: Embedded Microprocessor systems
 * Spring 2013
 */
#include "common.h"


void dtim0_delay(int p_usecs)
{
	MCF_DTIM0_DTRR = 4999 * p_usecs;
	MCF_DTIM0_DTCN &= 0;
			
	while(((MCF_DTIM0_DTER & ( 1 << 1 )) >> 1) != 1)
	{
	}
	MCF_DTIM0_DTER |= (1 << 1);
	
}

void dtim0_init()
{
	MCF_DTIM0_DTMR |= (1 << 1);
	MCF_DTIM0_DTMR |= (1 << 3);
	// MCF_DTIM0_DTMR |= (1 << 6);
	// MCF_DTIM0_DTMR &= ~(1 << 7);
	MCF_DTIM0_DTMR |= (0xF << 8); // DIVIDE BY 2^16 ON TIMER. ahhh... just got confused...
	MCF_DTIM0_DTMR |= 1;
}